const storage = window.localStorage;
var mystorage = {
  set: (key, value) => {
    if (!key) {
      return false;
    }

    let dataStr;
    try {
      dataStr = JSON.stringify(value);
    } catch (e) {
      console.log(e);
      dataStr = value;
    }
    storage.setItem(key, dataStr);
    return true;
  },

  get: (key) => {
    if (!key) {
      return undefined;
    }

    //读取
    let myData = storage.getItem(key);
    try {
      myData = JSON.parse(myData);
    } catch (error) {
      console.log(error);
    }
    return myData;
  },

  remove: (key) => {
    //读取
    var mydata = storage.getItem(key);
    if (!mydata) {
      return false;
    }
    storage.removeItem(key);
    return true;
  },
};

export default mystorage;
